<blockquote class="layui-elem-quote">
    <div class="layui-inline">
        <i class="layui-icon layui-icon-list layui-head-icon"></i>
        <span class="layui-font-16 layui-font-green">编辑文章</span>
    </div>
</blockquote>
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form">
            <input type="hidden" name="id" value="{$row.id}">
            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-inline">
                    <input type="number" name="sort" value="{$row.sort}" lay-verify="required" placeholder=""
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">选择分类</label>
                <div class="layui-input-block">
                    <select name="article_category_id" required lay-verify="required" class="layui-select">
                        <option value="">请选择文章分类</option>
                        {foreach $articleCategoryOptions as $opt}
                        <option value="{$opt.id}">{$opt.category_name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">文章标题</label>
                <div class="layui-input-block">
                    <input type="text" name="article_title" value="{$row.article_title}" required lay-verify="required"
                           placeholder="请输入文章标题" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">文章封面</label>
                <div class="layui-input-block">
                    <input type="hidden" name="article_cover" value="{$row.article_cover}" id="icon">
                    <img src="{notempty name='row.article_cover'} {$row.article_cover} {else/}  /static/admin/img/upimg.png {/notempty}"
                         id="upload" class="layui-long-upimg">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">文章内容</label>
                <div class="layui-input-block">
                    <textarea name="content" id="content" placeholder="请输入文章内容">{$row.content}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">阅读数</label>
                <div class="layui-input-inline">
                    <input type="number" name="view_count" value="{$row.view_count}" lay-verify="required"
                           placeholder="" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否启用</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" {if condition='$row.status==1' } checked {/if}
                    title="已发布">
                    <input type="radio" name="status" value="0" {if condition='$row.status==0' } checked {/if}
                    title="未发布">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formAdd">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    tinymce.init({
        selector: '#content',
        language: 'zh_CN',
        plugins: 'preview image emoticons table link hr anchor fullscreen lists',
        toolbar: 'bold italic underline strikethrough alignleft aligncenter alignright alignjustify indent outdent numlist bullist ' +
            'fontselect fontsizeselect forecolor backcolor blockquote removeformat ' +
            'emoticons image link hr anchor preview fullscreen',
        images_upload_url: '/store/upload/layedit',
        min_height: 500,
        setup: function (editor) {
            editor.on('change', function () {
                editor.save();
            });
        },
    });

    layui.use(['form', 'upload'], function () {
        var $ = layui.jquery, form = layui.form, upload = layui.upload;
        $('select[name="article_category_id"]').val("{$row.article_category_id}");
        form.render('select');
        upload.render({
            elem: "#upload",
            field: "image",
            url: "/store/upload",
            done: function (res) {
                if (res.code == 1) {
                    $('#upload').attr('src', res.src)
                    $('#icon').val(res.src);
                }
            }
        });

        form.on('submit(formAdd)', function (data) {
            $.post('/store/article/update', data.field, function (res) {
                if (res.code == 1) {
                   location.href = '/store/article'
                    return  false;
                }
                return layer.msg(res.msg, {icon: 2});
            });

            return false;
        });

    });
</script>
</body>
</html>